package com.zsgeek.wisdchain.qutu.view.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.zsgeek.wisdchain.qutu.BaseActivity;
import com.zsgeek.wisdchain.qutu.R;
import com.zsgeek.wisdchain.qutu.base.customControl.EmptyRecyclerView;
import com.zsgeek.wisdchain.qutu.base.customControl.LinearLayoutColorDivider;
import com.zsgeek.wisdchain.qutu.base.http.JsonRequest;
import com.zsgeek.wisdchain.qutu.base.http.JsonRequestCallBack;
import com.zsgeek.wisdchain.qutu.base.model.GetPartListModel;
import com.zsgeek.wisdchain.qutu.popup.dialog.DialogUtil;
import com.zsgeek.wisdchain.qutu.tools.TextUtils;
import com.zsgeek.wisdchain.qutu.tools.ToastHelper;
import com.zsgeek.wisdchain.qutu.tools.UrlPathHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 广告类型
 */
public class AdvertisementTypeActivity extends BaseActivity {
    //  @BindView(R.id.list_date_emptyView)
    // View list_date_emptyView;
    // @BindView(R.id.refreshLayout)
    // SmartRefreshLayout refreshLayout;
    @BindView(R.id.recyclerView)
    EmptyRecyclerView emptyRecyclerView;

    private List<GetPartListModel.DataBean> dataListBeans = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.activity_advertisement_type;
    }

    @Override
    protected void initView() {
        setTitle("广告类型");
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {
        getPartList();
    }

    /**
     * 2、标题栏接口
     */
    private void getPartList() {
        DialogUtil.createLoadingDialog(AdvertisementTypeActivity.this, null);
        new JsonRequest(new JsonRequestCallBack() {
            @Override
            public void showResult(Object object, String taskId) {
                if (object instanceof GetPartListModel) {
                    GetPartListModel dataModel = (GetPartListModel) object;
                    DialogUtil.closeLoadingDialog(AdvertisementTypeActivity.this);
                    if (dataModel.getCode() == 2000) {
                        dataListBeans = dataModel.getData();
                        if (!TextUtils.isEmpty(dataListBeans)) {
                            setView();
                        }

                    } else ToastHelper.showToast(dataModel.getMessage());
                }
            }

            @Override
            public void showError(String errorMsg, String taskId) {
                DialogUtil.closeLoadingDialog(AdvertisementTypeActivity.this);
                ToastHelper.showToast(errorMsg);
            }
        }).postJson(UrlPathHelper.getAdver() + "adver/getPartList", true, null, GetPartListModel.class);
    }

    private void setView() {
        emptyRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        emptyRecyclerView.addItemDecoration(new LinearLayoutColorDivider(this.getResources(),
                R.color.transparent, R.dimen.zero, LinearLayoutManager.VERTICAL));
        //emptyRecyclerView.setEmptyView(list_date_emptyView);
        BaseQuickAdapter<GetPartListModel.DataBean, BaseViewHolder> mAdapter =
                new BaseQuickAdapter<GetPartListModel.DataBean, BaseViewHolder>(R.layout.advertisement_type_item, dataListBeans) {
                    @Override
                    protected void convert(BaseViewHolder baseViewHolder, final GetPartListModel.DataBean dataBean) {
                        baseViewHolder.setText(R.id.title_tv, dataBean.getTitle());
                    }
                };
        emptyRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                setResult(-1, new Intent().putExtra("partId", dataListBeans.get(position).getId()));
                finish();
            }
        });
    }

}
